#!/bin/bash
echo -e "\033[34m Zerotier-one 树莓派自动安装脚本 \033[0m"
read -p "输入您的zerotier网络id:" netid
if [ ! $netid ]; then
echo -e "\033[34m Zerotier-one 网络Id不能为空. \033[0m"
exit 1
else
echo -e "\033[34m Zerotier-one 加入网络ID为:${netid} \033[0m"
fi

sudo rm -rf /var/lib/zerotier-one/networks.d/${netid}.conf
curl -s 'https://install.zerotier.com/' | sudo bash 

echo -e "\033[34m Zerotier-one 重新生成Id \033[0m"
sudo zerotier-idtool generate identity.secret identity.public
sudo systemctl restart zerotier-one.service
echo -e "\033[34m Zerotier-one 查看zerotier状态和本机ID \033[0m"
sudo zerotier-cli status

echo -e "\033[34m Zerotier-one 加入${netid}网络 \033[0m"
sudo zerotier-cli join $netid
echo -e "\033[34m Zerotier-one 请到zerotier控制中心授权本机 \033[0m"
echo -e "\033[34m Zerotier-one 查看连线状态 \033[0m"
sudo zerotier-cli listnetworks
sudo touch /var/lib/zerotier-one/networks.d/${netid}.conf


echo '查看网卡状态'
echo -e "\033[34m Zerotier-one 查看网卡状态 \033[0m"
ifconfig

echo '如果没看到“zt0:”开头的网卡请重启树莓派'

echo -e "\033[31m 请打开Zerotier后台，授权树莓派后才能分配到IP\033[0m" 